<?php

namespace App\Http\Validate\SystemNotify;

use App\Http\Validate\AbstractBaseValidate;
use App\Models\System\SystemNotifyCenterModel;
use Illuminate\Support\Carbon;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class SystemNotifyValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    /**
     * 延时消息推送校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function delayPushValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id", "delayNotifyTime"],
            $params,
            [
                "id"              => [
                    "required",
                    "int",
                    "min:1",
                    Rule::exists((new SystemNotifyCenterModel())->getTable(), "id")
                        ->where("status", SystemNotifyCenterModel::NOTIFY_STATUS_1)
                        ->where("isDeleted", 0)
                ],
                "delayNotifyTime" => [
                    "required",
                    "date_format:Y-m-d H:i:s",
                    "after:" . Carbon::now()->addMinutes(3)->format("Y-m-d H:i:s"),
                    "before:" . Carbon::now()->addDays(7)->format("Y-m-d H:i:s")
                ]
            ]
        );
    }

    /**
     * 延时消息推送校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function cancelDelayPushValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id"],
            $params,
            [
                "id" => [
                    "required",
                    "int",
                    "min:1",
                    Rule::exists((new SystemNotifyCenterModel())->getTable(), "id")
                        ->where("status", SystemNotifyCenterModel::NOTIFY_STATUS_1)
                        ->where("notifyType", SystemNotifyCenterModel::NOTIFY_TYPE_DELAY)
                        ->where("isDeleted", 0)
                ]
            ]
        );
    }
}
